<template>
  <div>
    <el-form class="query-table-form" @submit.native.prevent :inline="true" :model="params">
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          placeholder="项目名称查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.corp_name"
          placeholder="负责人查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <select-address
          v-model="params.address_code"
          placeholder="地址查询"
          auto-top
          clearable
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button
          icon="el-icon-download"
          :loading="exportLoading"
          @click="exportExcel('贷后管理（在保项目）')"
        >
          导出
        </el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:address="scope">
        <el-tooltip effect="light" :content="scope.row.address">
          <div class="text-truncate">{{ scope.row.address }}</div>
        </el-tooltip>
      </template>

      <template v-slot:projectEleStatus="scope">
        <span class="badge" :class="`badge-${scope.row.projectEleStatusStyle}`">
          {{ scope.row.projectEleStatusLabel }}
        </span>
      </template>
    </c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <!-- <el-dialog :visible.sync="reportVisible"
               :close-on-click-modal="false"
               :before-close="beforeClose"
               append-to-body
               top="30px"
               width="80%">
      <el-tabs v-model="activeName">
        <el-tab-pane label="调查报告"
                     name="file">
          <credit-file :query-id="queryId"
                       :viewMode="true"></credit-file>
        </el-tab-pane>
        <el-tab-pane label="放款登记">
          <register-reply :related-data="fileData"
                          :view-mode="true"></register-reply>
        </el-tab-pane>
        <el-tab-pane label="担保意向函"
                     v-if="+fileData.is_history !== 1"
                     name="letter">
          <letter-view :related-data="fileData"></letter-view>
        </el-tab-pane>
        <el-tab-pane label="放款通知书"
                     v-if="+fileData.is_history !== 1"
                     name="notice">
          <register-loan-notice :related-data="fileData"
                                view-mode></register-loan-notice>
        </el-tab-pane>
        <el-tab-pane label="联保函"
                     v-if="+fileData.is_history !== 1">
          <union-letter :related-data="fileData"
                        :isView="true"></union-letter>
        </el-tab-pane>
        <el-tab-pane label="附件">
          <attach-view :queryId="queryId"
                       :visible="reportVisible"></attach-view>
        </el-tab-pane>
      </el-tabs>
    </el-dialog> -->
    <postloan-file :visible.sync="reportVisible" :related-data="fileData"></postloan-file>
    <attach-cmpt :visible.sync="attachVisible" :customer-related-id="attachRelatedId"></attach-cmpt>
  </div>
</template>

<script>
import SelectAddress from '@/components/select/SelectAddress'
// import AttachView from '@/credit/components/AttachView'
// import LetterView from '@/credit/views/county/mission/components/LetterView'
// import RegisterLoanNotice from '@/credit/views/county/mission/RegisterLoanNotice'
// import UnionLetter from '@/credit/views/county/mission/components/UnionLetter'
import taskTableMixin from '@/credit/mixin/mission/taskTable'
// import RegisterReply from '@/credit/views/county/mission/RegisterReply'
import { enumGuatype } from '@/credit/plugins/enumTown'
import { enumRenewalStatus } from '@/credit/plugins/enum'
import AttachCmpt from '@/credit/views/city/program/Attach'
import PostloanFile from '@/credit/views/city/mission/PostloanFile'
export const postloanTableColumns = [
  {
    attrs: { label: '主体名称', prop: 'customer_name', minWidth: '120px' },
    process: (v, row) => ({
      attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
    }),
  },
  { attrs: { label: '业务类型', prop: 'guaType', align: 'center' } },
  { attrs: { label: '地址', prop: 'address' }, slot: 'address' },
  { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
  { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center' } },
  { attrs: { label: '放款金额(万元)', prop: 'reply_funds', align: 'center' } },
  { attrs: { label: '在保余额', prop: 'left_funds', align: 'center' } },
  { attrs: { label: '到期时间', prop: 'endDate', align: 'center' } },
  { attrs: { label: '贷后状态', prop: 'renewalStatus', align: 'center' } },
]

export default {
  components: {
    SelectAddress,
    // LetterView,
    // RegisterLoanNotice,
    // UnionLetter,
    // CreditFile,
    // RegisterReply,
    // AttachView,
    AttachCmpt,
    PostloanFile,
  },
  mixins: [taskTableMixin],
  props: {},
  data() {
    return {
      params: {
        index: 1,
        size: 10,
        customer_name: '',
        corp_name: '',
        address_code: '',
        'gua_type.eq': 1,
        'loan_notice_status.eq': 2,
        'load_beh_status.eq': 1,
      },
      order: {
        N2create_time: 'DESC',
      },
      attachVisible: false,
      attachRelatedId: '',
      tableName: 'customer_related',
      tableColumns: [
        ...postloanTableColumns,
        {
          attrs: { label: '操作', align: 'center', minWidth: 120 },
          operations: [
            { content: '上传附件', icon: 'fa fa-clipboard', event: this.hanleAttach },
            {
              content: '贷后详情',
              icon: 'fa fa-edit',
              event: this.handleEdit,
            },
            {
              content: '查看',
              icon: 'fa fa-search',
              event: this.hanleView,
            },
          ],
        },
      ],
      dateFmt: 'yyyy-MM-dd',

      activeName: 'file',

      // 档案卡
      queryId: '',
      reportVisible: false,
      fileData: {},
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getData()
  },
  mounted() {},
  methods: {
    hanleAttach(row) {
      this.attachVisible = true
      this.attachRelatedId = row.customer_related_id
    },
    dataAdapter(item) {
      item.guaType = enumGuatype[item.gua_type] || '-'
      item.endDate = this.$utils.dateFormat(item.load_end_date, this.dateFmt)
      item.renewalStatus = enumRenewalStatus[item.load_beh_status] || '-'
      return item
    },
    handleEdit(row = {}) {
      this.$router.push({
        name: 'missionAfter',
        query: {
          id: row.customer_related_id,
          farmid: row.customer_id,
        },
      })
    },
    hanleView(row = {}) {
      this.fileData = row
      this.queryId = this.fileData.customer_related_id
      this.reportVisible = true
    },
    beforeClose() {
      this.reportVisible = false
      setTimeout(() => (this.activeName = 'file'), 200)
    },
  },
}
</script>
<style lang="scss" scoped></style>
